/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: StringTest.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/9 下午6:22
 * LastModified: 2020/03/09 18:22:09
 */

package com.qolome.knowledge.design.pattern.flyweight.jdk;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Qolome
 * @version V1.0
 * @Description String测试
 * @date 2020年 03月09日 18:22:12
 */
@Slf4j
public class StringTest {


    public static void main(String[] args) {
        // String 利用享元模式 ,声明出的真实参数(非引用参数),将使用同一个内存地址
        // Java在编译期间对常量做处理,但不对变量做处理
        String s1 = "hello";
        String s2 = "hello";
        String s3 = "hel"+"lo";
        String s4 = "hel"+new String("lo");
        String s5 = new String("hello");
        String s6 = s5.intern();
        String s7 = "h";
        String s8 = "ello";
        String s9 = s7+s8;
        //true
        System.out.println(s1==s2);
       //true
        System.out.println(s1==s2);
        //true
        System.out.println(s1==s3);
        //false
        System.out.println(s1==s4);
        // false
        System.out.println(s1==s5);
        // false
        System.out.println(s4==s5);
        // true
        System.out.println(s1==s6);
        // false
        System.out.println(s1==s9);


    }
}
